package com.ss.android.wenda.ui;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;

import java.util.ArrayList;

public class MultiStyleTextView extends View {
    public int a;
    public String b;
    public String c;
    public boolean d;
    private Resources e;
    private int f;
    private int g;
    private Paint h;
    private Paint i;
    private Paint.FontMetrics j;
    private Paint.FontMetrics k;
    private float l;
    private float m;
    private ArrayList n;
    private int o;
    private boolean p;
    private boolean q;

    public MultiStyleTextView(Context arg3) {
        super(arg3);
        this.o = -1;
        this.d = false;
        this.p = false;
        this.q = false;
        this.a();
    }

    public MultiStyleTextView(Context arg3, AttributeSet arg4) {
        super(arg3, arg4);
        this.o = -1;
        this.d = false;
        this.p = false;
        this.q = false;
        this.a();
    }

    public MultiStyleTextView(Context arg3, AttributeSet arg4, int arg5) {
        super(arg3, arg4, arg5);
        this.o = -1;
        this.d = false;
        this.p = false;
        this.q = false;
        this.a();
    }

    private void a() {
        this.e = this.getResources();
        DisplayMetrics v0 = this.e.getDisplayMetrics();
        this.a = ((int)TypedValue.applyDimension(1, 8f, v0));
        this.f = ((int)TypedValue.applyDimension(1, 17f, v0));
        this.g = ((int)TypedValue.applyDimension(1, 3f, v0));
        int v1 = this.e.getColor(com.ss.android.article.browser.R.color.ssxinzi1);
        int v2 = this.e.getColor(com.ss.android.article.browser.R.color.ssxinzi3);
        float v3 = TypedValue.applyDimension(2, 16f, v0);
        float v0_1 = TypedValue.applyDimension(2, 12f, v0);
        this.h = new Paint();
        this.h.setAntiAlias(true);
        this.h.setTextAlign(Paint.Align.LEFT);
        this.h.setColor(v1);
        this.h.setTextSize(v3);
        this.i = new Paint();
        this.i.setAntiAlias(true);
        this.i.setTextAlign(Paint.Align.LEFT);
        this.i.setColor(v2);
        this.i.setTextSize(v0_1);
        this.j = this.h.getFontMetrics();
        this.k = this.i.getFontMetrics();
        this.l = this.j.descent - this.j.ascent;
        this.m = this.k.descent - this.k.ascent;
        this.n = new ArrayList();
    }

    private void b() {
        String v0 = this.b == null ? "" : this.b;
        this.b = v0;
        v0 = this.c == null ? "" : this.c;
        this.c = v0;
    }

    private int getLineCount() {
        int v1;
        MultiStyleTextView v0_1;
        boolean v4_1;
        float v10 = 0.999f;
        int v4 = 1;
        int v2 = 0;
        if(!TextUtils.isEmpty(this.b)) {
            if(this.o > 0 && !this.d) {
                return this.o;
            }

            this.d = false;
            this.b();
            int v7 = this.getMeasuredWidth();
            if(v7 == 0) {
                return v2;
            }

            int v0 = ((int)(this.h.measureText(this.b) + v10));
            int v8 = ((int)(this.i.measureText(this.c) + v10));
            if(v0 + v8 + this.a <= v7) {
                this.p = false;
            }
            else {
                if(v0 >= v7 || v0 + v8 + this.a <= v7) {
                    int v9 = this.getMeasuredWidth();
                    String v1_1 = this.b;
                    this.n.clear();
                    while(true) {
                        v0 = this.h.breakText(((CharSequence)v1_1), 0, v1_1.length(), true, ((float)v9), null);
                        if(v0 == v1_1.length()) {
                            break;
                        }

                        this.n.add(v1_1.substring(0, v0));
                        v1_1 = v1_1.substring(v0);
                    }

                    this.n.add(v1_1);
                    float v1_2 = ((float)(((int)(this.h.measureText((String) this.n.get(this.n.size() - 1)) + v10))));
                    v0 = this.n.size();
                    if(v1_2 + (((float)v8)) + (((float)this.a)) > (((float)v7))) {
                        v1 = v0;
                        v0_1 = this;
                        v4_1 = true;
                    } else {
                        v4_1 = false;
                        v1 = v0;
                        v0_1 = this;
                    }
                } else {
                    v0_1 = this;
                    v1 = 1;
                    v4_1 = true;
                }

                v0_1.p = v4_1;
                v4 = v1;
            }

            this.o = v4;
            v2 = this.o;
        }

        return v2;
    }

    protected void onDraw(Canvas arg13) {
        float v0;
        float v11 = 2f;
        float v10 = 0.999f;
        super.onDraw(arg13);
        if(!TextUtils.isEmpty(this.b)) {
            this.b();
            int v2 = this.getMeasuredWidth();
            int v1 = this.getMeasuredHeight();
            int v3 = ((int)(this.h.measureText(this.b) + v10));
            int v4 = ((int)(this.i.measureText(this.c) + v10));
            int v5 = this.getLineCount();
            if(v5 > 0) {
                if(v5 != 1) {
                    if(this.p) {
                        v2 = this.n.size();
                        for(v1 = 0; true; ++v1) {
                            if(v1 >= v2) {
                                return;
                            }

                            arg13.drawText((String) this.n.get(v1), 0f, (((float)this.f)) - this.j.ascent + (((float)v1)) * (this.l + (((float)this.g))), this.h);
                            if(v1 == v2 - 1) {
                                arg13.drawText(this.c, 0f, (((float)this.f)) + (((float)(v1 + 1))) * (this.l + (((float)this.g))) - this.k.ascent, this.i);
                            }
                        }
                    }

                    v3 = this.n.size();
                    for(v1 = 0; v1 < v3; ++v1) {
                        Object v0_1 = this.n.get(v1);
                        arg13.drawText(((String)v0_1), 0f, (((float)this.f)) - this.j.ascent + (((float)v1)) * (this.l + (((float)this.g))), this.h);
                        if(v1 == v3 - 1) {
                            v0 = ((float)(((int)(this.h.measureText(((String)v0_1)) + v10))));
                            if(this.q) {
                                v0 = ((float)(v2 - v4));
                            }
                            else {
                                v0 += ((float)this.a);
                            }

                            arg13.drawText(this.c, v0, (((float)this.f)) + (((float)v1)) * (this.l + (((float)this.g))) + (this.l - this.k.ascent - this.k.descent) / v11, this.i);
                        }
                    }
                }
                else if(this.p) {
                    arg13.drawText(this.b, 0f, (((float)this.f)) - this.j.ascent, this.h);
                    arg13.drawText(this.c, 0f, (((float)this.f)) + this.l + (((float)this.g)) - this.k.ascent, this.i);
                }
                else {
                    arg13.drawText(this.b, 0f, ((((float)v1)) - this.j.ascent - this.j.descent) / v11, this.h);
                    v0 = this.q ? ((float)(v2 - v4)) : ((float)(this.a + v3));
                    arg13.drawText(this.c, v0, ((((float)v1)) - this.k.ascent - this.k.descent) / v11, this.i);
                }
            }
        }
    }

    protected void onMeasure(int arg6, int arg7) {
        float v4 = 0.999f;
        if(!TextUtils.isEmpty(this.b)) {
            int v0 = this.getLineCount();
            v0 = this.p ? ((int)((((float)(v0 * this.g))) + ((((float)(this.f * 2))) + this.l * (((float)v0))) + this.m + v4)) : ((int)((((float)((v0 - 1) * this.g))) + ((((float)(this.f * 2))) + this.l * (((float)v0))) + v4));
            arg7 = View.MeasureSpec.makeMeasureSpec(v0, MeasureSpec.EXACTLY);
        }

        super.onMeasure(arg6, arg7);
    }

    public void setAlignRight(boolean arg1) {
        this.q = arg1;
    }

    public void setAnswerCountTextColor(int arg2) {
        this.i.setColor(arg2);
    }

    public void setAnswerCountTextSize(float arg3) {
        this.i.setTextSize(arg3);
        this.k = this.i.getFontMetrics();
        this.m = this.k.descent - this.k.ascent;
    }

    public void setLineSpacing(int arg1) {
        this.g = arg1;
    }

    public void setMultiLineVerticalPadding(int arg1) {
        this.f = arg1;
    }

    public void setPadding(int arg1) {
        this.a = arg1;
    }

    public void setQuestionTextColor(int arg2) {
        this.h.setColor(arg2);
    }

    public void setQuestionTextSize(float arg3) {
        this.h.setTextSize(arg3);
        this.j = this.h.getFontMetrics();
        this.l = this.j.descent - this.j.ascent;
    }

    public void setQuestionTextType(Typeface arg2) {
        this.h.setTypeface(arg2);
    }
}

